$(function () {
  function git() {
    $.ajax({
      method: "GET",
      url: "http://www.liulongbin.top:3006/api/cmtlist",
      success: function (res) {
        console.log(res);
        if (res.status !== 200) {
          return alert("2");
        }
        var row = [];
        $.each(res.data, function (i, item) {
          var str = ` <li class="list-group-item">
          <a href="javascript:;" class="badge" style="background-color: #d9534f" data-id="${item.id}">删除</a><span class="badge" style="background-color: #F0AD4E;">评论时间：${item.time}</span><span class="badge" style="background-color: #5BC0DE;">评论人：${item.username}</span>${item.content}
            </li>`;
          row.push(str);
        });

        $("#cmt-list").empty().append(row.join(""));
      },
    });
  }
  git();
  $.ajax({
    method: "POST",
    url: "http://www.liulongbin.top:3006/api/addcmt",
    data: {
      username: 'username',
      content: 'content',
    },
    success: function (res) {
      if (res.status !== 201) {
        return alert("s");
      }
      getCommentList();
      $("#formAddCmt")[0].reset();
    },
  });
});
